package com.zthz.douxing.sendmessageservice.thirdmessagesender

import com.tencent.xinge.Message
import com.zthz.douxing.event.UserWillDepartEvent
import com.zthz.douxing.event.XinGeMessageEvent
import com.zthz.douxing.msg.MessageType
import com.zthz.douxing.msg.XingeMessageResult
import com.zthz.douxing.utils.CommonUtil

class XinGeMessageSenderService implements BaseMessageSenderService{

    def messageSenderService

    def send2XingeMsg(XinGeMessageEvent event) {

        Message msg = new Message()
        msg.title = event.title
        msg.content = event.content
        msg.type =  Message.TYPE_MESSAGE

        return messageSenderService.sendMessageToOne(event.platformType,event.xgToken,msg)
    }

    @Override
    def getParamFromUserWillDepartEvent4PlanForm(UserWillDepartEvent event, String msgContent,MessageType messageType) {
        XinGeMessageEvent xingeEvent = new XinGeMessageEvent()
        xingeEvent.xgToken = event.xgToken
        xingeEvent.content =  msgContent
        xingeEvent.platformType = CommonUtil.getPlantform2MessageApp(event.platformType)
        xingeEvent.title = messageType.name()
        xingeEvent.msgType = messageType

        return null
    }

    @Override
    def send2One(Object obj) {
        try {
            if(obj instanceof UserWillDepartEvent){
                return new XingeMessageResult().getSendStatus(send2XingeMsg((UserWillDepartEvent)obj).ret_code)
            }else{
                return null
            }
        }catch (Exception e){
            log.error(e.getMessage(),e.printStackTrace())
            return e.printStackTrace()
        }
    }

    @Override
    def send2Many(Map parm) {
        return null
    }
}
